package com.zzyl.controller.web;


import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.NursingPlanDto;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 护理计划表 前端控制器
 * </p>
 *
 * @author author
 * @since 2024-08-15
 */
@RestController

public class NursingPlanController extends BaseController {
    @Autowired
    private NursingPlanService nursingPlanService;

    //分页查询
    @GetMapping("/nursing/plan/search")
    public ResponseResult findByIdPage(String name, Integer status,
                                       @RequestParam(defaultValue = "1") Integer pageNum,
                                       @RequestParam(defaultValue = "10")Integer pageSize){
        PageResponse<NursingPlan> pageResponse = nursingPlanService.findByIdPage(name,status,pageNum,pageSize);
        return success(pageResponse);
    }

    //新增
    @PostMapping("/nursing/plan")
    public ResponseResult save(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.saveNursingPlan(nursingPlanDto);
        return success();

    }

    //主键查询
    @GetMapping("/nursing/plan/{id}")
    public ResponseResult findById(@PathVariable Long id){
        NursingPlanVo nursingPlanVo = nursingPlanService.findById(id);
        return success(nursingPlanVo);
    }

    //修改
    @PutMapping("/nursing/plan/{id}")
    public ResponseResult update(@RequestBody NursingPlanDto nursingPlanDto){
        nursingPlanService.updateNursingPlan(nursingPlanDto);
        return success();
    }

    //删除
    @DeleteMapping("/nursing/plan/{id}")
    public ResponseResult delete(@PathVariable Long id){
        nursingPlanService.delete(id);
        return success();
    }

    //启用禁用
    @PutMapping("/nursing/{id}/status/{status}")
    public ResponseResult switchStatus(@PathVariable Long id,@PathVariable Integer status){
        nursingPlanService.switchStatus(id,status);
        return success();
    }

    //查询所有
    @GetMapping("/nursing/plan")
    public ResponseResult getAll(){
        List<NursingPlan> list = nursingPlanService.list();
        return success(list);
    }
}
